package imper.engine.util;

import imper.engine.entity.Facilities;
import imper.engine.entity.Land;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class FacilitiesManager
{
	protected Map<FacilitiesCategoryEnum, Set<Integer>> _facilities;

	public FacilitiesManager()
	{
		_facilities = new HashMap<FacilitiesCategoryEnum, Set<Integer>>();
	}

	public void add(FacilitiesCategoryEnum pEnum, Integer pId)
	{
		Set<Integer> set = _facilities.get(pEnum);
		if (set == null)
		{
			set = new HashSet<Integer>();
			_facilities.put(pEnum, set);
		}
		set.add(pId);
	}

	public boolean isFacilitiesCategory(FacilitiesCategoryEnum pEnum, Integer pId)
	{
		Set<Integer> set = _facilities.get(pEnum);
		if (set != null && set.contains(pId))
		{
			return true;
		}
		return false;
	}

	public boolean isFacilitiesCategory(FacilitiesCategoryEnum pEnum, List<Facilities> pList)
	{
		for (Facilities facilities : pList)
		{
			boolean isFacilitiesCategory = isFacilitiesCategory(pEnum, facilities.getFacilitiesTypeId());
			if (isFacilitiesCategory)
			{
				return true;
			}
		}
		return false;
	}

	public boolean isFacilitiesCategory(FacilitiesCategoryEnum pEnum, Land pLand)
	{
		return isFacilitiesCategory(pEnum, pLand.getFacilities());
	}
}
